<style lang="less">
    @import '../../styles/common.less';
</style>

<template>
<div>
        <i-Form :model="editData" :label-width="100">
      
                <Card>  
        <p slot="title">
            <Icon type="navicon-round"></Icon>
            简信息<span>{{pagename}}</span>
        </p>

        <p style="margin:10px 0;">
           <Form-item label="标题">
                <i-Input type="text" v-model="editData.title" placeholder="标题"></i-Input>
            </Form-item>
            <Form-item label="英文标题">
                <i-Input type="text" v-model="editData.etitle" placeholder="英文标题">
                </i-Input>
            </Form-item>            
            <Form-item label="标识">
                <i-Input type="text" v-model="editData.flag" placeholder="标识(唯一与其他页面内容不同，建议使用英文)">
                </i-Input>
            </Form-item>       
            <Form-item label="内容">
                 <UEditor id="content" :config="config" ref="content"></UEditor>
            </Form-item>  
            <Form-item>
                <i-button type="primary" @click="save">提交</i-button>
            </Form-item>
        </p>
    </Card>
        </i-Form>
    </div>
    
</template>

<script>
import UEditor from '@/ueditor/ueditor.vue'
import api from '../../libs/api';
export default {
    name: 'content_jxinxiadd',
      components: {UEditor},
    data () {
        return {config: {
            //可以在此处定义工具栏的内容
            // toolbars: [
            //  ['fullscreen', 'undo', 'redo','|','bold', 'italic', 'underline',
            //  '|','superscript','subscript','|', 'insertorderedlist', 'insertunorderedlist',
            //  '|','fontfamily','fontsize','justifyleft','justifyright','justifycenter','justifyjustify']
            // ],
            autoHeightEnabled: false,
            autoFloatEnabled: true,
            initialContent:'',   //初始化编辑器的内容,也可以通过textarea/script给值，看官网例子
            autoClearinitialContent:true, //是否自动清除编辑器初始内容，注意：如果focus属性设置为true,这个也为真，那么编辑器一上来就会触发导致初始化的内容看不到了
            initialFrameWidth: null,
            initialFrameHeight: 450,
            BaseUrl: '',
            themePath:'/static/ueditor/themes/',
            UEDITOR_HOME_URL: '/static/ueditor/',
            wordCount:false
          },
            mode:"PC",
            ismobile:false,
            pagename:"添加",
            editData:{content:'<p></p>'},
            categorylist:[],
            imgName: '',
            visible: false,
        };
    },
    methods: {
        save(){            
            var vm=this;   
            this.editData.content=this.$refs.content.getUEContent();
            api.post("/jxinxi/save",this.editData).then(function(res){
                if(vm.editData.ID>0)
                    vm.$Message.success("修改成功！");
                else                    
                    vm.$Message.success("添加成功！");
                    vm.$router.push({
                        name: 'content_jxinxi',
                        query: {}
                    });
            })
        },
        init () {
            var vm=this;
            var id=this.$route.query.ID;
            if(id>0){
                this.pagename="编辑"; 
                api.get("/jxinxi/get/"+id).then(function(res){
                    vm.editData=res.data.msg;                    
                    delete  vm.editData.sid;
                    delete  vm.editData.mid;                    
                if(vm.editData.content==undefined){
                    vm.editData.content="";
                }     
                vm.$refs.content.ready(function() {                                
                    vm.$refs.content.setUEContent(vm.editData.content);
                })
                })
            }
            else{
                this.pagename="添加";             
                this.$nextTick(() => {

                })
            }
        }
    },
    mounted () {
        this.init();
    },
    watch: {
        '$route' () {
            this.init();
        }
    }

};
</script>
